package com.example.demo.controller.system;

import com.example.demo.model.ResponseMessage;
import com.example.demo.model.system.Role;
import com.example.demo.service.system.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/role")
public class RoleController {

  @Autowired
  private RoleService service;

  @RequestMapping("save")
  public ResponseMessage save(Role role){
    ResponseMessage responseMessage = new ResponseMessage();
    Boolean flag = service.save(role);
    responseMessage.setFlag(flag);

    return  responseMessage;
  }

  @ResponseBody
  @RequestMapping("selectByRoleId")
  public Role selectByRoleId(Integer role_id){ return service.selectByRoleId(3); }

  @ResponseBody
  @RequestMapping("selectAll")
  public List<Role> selectAll(){return service.selectAll();}

  @RequestMapping("findRole")
  @ResponseBody
  public List<Role> findRole(String role_name,String desc){ return service.findRole(role_name,desc);}

  @RequestMapping("addRole")
  public Integer addRole(Role role){return service.addRole(role);}

  @RequestMapping("deleteById")
  public Boolean deleteById(Integer role_id){return service.deleteById(role_id)==1;}

  @RequestMapping("updateById")
  public Integer updateById(Role role){return service.updateById(role);}
}